#ifndef BUFFERDB_H
#define BUFFERDB_H

#include <google/protobuf/message.h>
#include <google/protobuf/descriptor.h>
#include <boost/asio.hpp>

using boost::asio::ip::tcp;
using namespace google::protobuf;
using namespace std;
//using boost::asio::ip::tcp;
#include "../proto/database.pb.h"

class bufferDB
{
	public: bufferDB(void);
			void setNewMessage(db::Database*);
			//Serialize Method
			void serializeAndSend(char*);
			void serializeAndListen(char*);
			void setWrite(bool);
			void setRepeatedMsgPtr(int);
			void AddNestedMsgElement();
			void setFieldPtr(int);
			void setNestedTypePtr(int);
			void setNestedTokenTypePtr(int);
			void setMessageEntryPtr(int);						
			int findRepeatedFields();
			int	findNestedTypes();
			int findNestedTokenTypes();

			db::Database *msg;

		   tcp::iostream *thestream;

	protected:
			//Variables changed by getField methods
			string stringData;
			float floatData;
			int int32Data;
			bool boolData;
			double doubleData;

			int	repeatedFieldMap[100];
			
			int getFieldCnt();
			int getEntryCnt();
						
			//Set and Get Data Methods
			void getSingleFieldData();
			void setSingleFieldFromString(string);
			void getRepeatedFieldData(int);
			void setRepeatedFieldFromString(string, int);
			void getNestedSingleFieldData();
			void setNestedSingleFieldFromString(string);			
			void getNestedRepeatedFieldData(int);
			void setNestedRepeatedFromString(string, int);
			
			int EntryNum;
			bool getNestedBool();
			string getNestedString();
			int32 getNestedInt32();
			double getNestedDouble();
			float getNestedFloat();
			
			//Field Name Getters
			string getFieldName();
			string getNestedMessageName();	
			string getNestedTokenName();
			
			//Field Type Getters
			FieldDescriptor::CppType getFieldType();
			FieldDescriptor::CppType getNestedTokenType();
			string serialData;	
			string receivedData;		
			Message* nestedMsg;
			const Descriptor* msgDescript;
			const Reflection* msgReflect;
			const FieldDescriptor* msgField;
						
			const Descriptor* nestedDescript;
			const Reflection* nestedReflect;
			const Reflection* nestedEntryReflect;			
			const FieldDescriptor* nestedField;
};

#endif			
			

			
